package com.flot.yazb.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;

//import com.antfortune.freeline.FreelineCore;
import com.flot.yazb.BuildConfig;
import com.flot.yazb.ChannelManage;
import com.flot.yazb.model.other.SetModle;
import com.flot.yazb.model.user.UserModel;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fengdongfei on 2017/8/24.
 */

public class BApplication extends Application {

    public static String APIHOST =BuildConfig.HOST_URL;
    private static BApplication instance = null;
    private static Context sContext = null;
    private static List<Activity> activities = new ArrayList<>();
    private static UserModel userModel;
    private static SetModle setModle;


    @Override
    public void onCreate() {
        super.onCreate();
        sContext = getApplicationContext();
        userModel=new UserModel();
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        //友盟错误统计
        MobclickAgent.setScenarioType(getContext(), MobclickAgent.EScenarioType.E_UM_NORMAL);
        MobclickAgent.setCatchUncaughtExceptions(true);
        MobclickAgent.setDebugMode( true );
        MobclickAgent.startWithConfigure(new MobclickAgent.UMAnalyticsConfig(getApplicationContext(),"59b110b6cae7e71a7b000632", ChannelManage.getChannel(this)));
    }

    public static BApplication getInstance() {
        if (null == instance) {
            instance = new BApplication();
        }
        return instance;
    }

    public UserModel getUserModel(){
        if (null==userModel){
            userModel=new UserModel();
        }
        return userModel;
    }

    public void setUserModel(UserModel model){
        if (null==userModel){
            userModel=new UserModel();
        }
        userModel=model;
    }

    /**
     * 获取配置信息
     * @return
     */
    public SetModle getsettModel(){
        if (setModle==null){
            setModle=new SetModle();
        }
        return setModle;
    }

    public void setSetModel(SetModle model){
        if (null==setModle){
            setModle=new SetModle();
        }
        setModle=model;
    }

    public static Context getContext() {
        return sContext;
    }


    public static void addActivity(Activity activity) {
        if (!activities.contains(activity)) {
            activities.add(activity);
        }
    }

    public static void closeAllActivities() {
        for (Activity a : activities) {
            if (a != null) {
                a.finish();
            }
        }
        activities.clear();
    }

    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }


}
